package com.milk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.milk.entity.Carousels;
import com.milk.mapper.CarouselsMapper;
import com.milk.service.ICarouselsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.milk.vo.CarouselsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页轮播图 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-03-27
 */
@Service
public class CarouselsServiceImpl extends ServiceImpl<CarouselsMapper, Carousels> implements ICarouselsService {
    @Autowired
    private CarouselsMapper carouselsMapper;

    /**
     * 查询所有轮播图
     * @return
     */
    public CarouselsVO selectAll() {
        CarouselsVO carouselsVO = new CarouselsVO();
        List<Carousels> carousels = carouselsMapper.selectList(new QueryWrapper<>());
        //取出点单跳转图片
        Carousels imageUrl = carousels.get(carousels.size() - 1);
        carouselsVO.setImageUrl(imageUrl.getImage());
        //从轮播图列表中删除点单跳转图片
        carousels.remove(imageUrl);
        carouselsVO.setList(carousels);
        return carouselsVO;
    }
}
